package com.ybb.vue.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ybb.vue.entity.SysMenu;
import com.ybb.vue.mapper.SysMenuMapper;
import com.ybb.vue.service.SysMenuService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author ybb
* @description 针对表【sys_menu】的数据库操作Service实现
*/
@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService {

    @Override
    public List<SysMenu> buildTreeMenu(List<SysMenu> sysMenuList) {
        List<SysMenu> menuTree = new ArrayList<>();
        for (SysMenu sysMenu : sysMenuList) {

            for (SysMenu e : sysMenuList) {
                if (e.getParentId() == sysMenu.getId()) {
                    // 添加子节点
                    sysMenu.getChildren().add(e);
                }
            }
            // 为顶级父节点
            if (sysMenu.getParentId() == 0L) {
                menuTree.add(sysMenu);
            }
        }

        return menuTree;
    }
}




